package com.demo.base.rabbitmq.queue;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.demo.base.rabbitmq.constant.MqConstant.*;

/**
 * @author 曳戈泰尔
 * @version 1.0
 * @description 队列、交换机、绑定配置 实时
 * @date 2023/3/10 4:42 PM
 */
@Configuration
public class MqRealTimeQueue {

    /**
     * 创建实时队列
     *
     * @return
     */
    @Bean
    public Queue realTimeQueue() {
        return new Queue(REAL_TIME_QUEUE, true);
    }

    /**
     * 创建实时交换机 路由模式 实时消息
     *
     * @return
     */
    @Bean
    public DirectExchange realTimeExchange() {
        return new DirectExchange(REAL_TIME_EXCHANGE, true, false);
    }

    /**
     * 绑定实时消息、交换机、路由
     *
     * @return
     */
    @Bean
    public Binding realTimeBind() {
        return BindingBuilder.bind(realTimeQueue())
                .to(realTimeExchange())
                .with(REAL_TIME_ROUTING_KEY);
    }
}
